﻿package mortal.game.view.relive.parts
{
    import Message.Public.*;
    import com.gengine.core.frame.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.component.gconst.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;

    public class ReliveLeftSecondPart extends GSprite
    {
        private var _bmp1:GBitmap;
        private var _bmp2:GBitmap;
        private var _btn:GLoadingButton;
        private var _text:BitmapNumberText;
        private var _sectimer:SecTimer;
        private var _total:int;
        private var _cur:int;
        private var _callback:Function;

        public function ReliveLeftSecondPart()
        {
            return;
        }// end function

        public function showHideBtn(param1:Boolean = false) : void
        {
            if (param1 && this._btn.parent == null)
            {
                this.addChild(this._btn);
            }
            else
            {
                DisplayUtil.removeMe(this._btn);
            }
            return;
        }// end function

        public function hideTimer() : void
        {
            DisplayUtil.removeMe(this._bmp1);
            DisplayUtil.removeMe(this._bmp2);
            if (this._sectimer.running)
            {
                this._sectimer.stop();
            }
            DisplayUtil.removeMe(this._text);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._sectimer = new SecTimer(1);
            this._sectimer.addListener(TimerType.ENTERFRAME, this.secTimerHandler);
            this._bmp1 = UIFactory.gBitmap("", 10, 0, this);
            this._bmp2 = UIFactory.gBitmap("", 140, 0, this);
            this._text = UIFactory.bitmapNumberText(50, -10, "ReliveNum.png", 41, 43, -6, this, 9);
            this._btn = UIFactory.gLoadingButton(ImagesConst.ReliveNearestBtn_upSkin, 27, 50, 157, 39, this);
            LoaderHelp.addResCallBack(ResFileConst.relivePanel, this.resGotHandler);
            this._btn.configEventListener(MouseEvent.CLICK, this.cityReliveHandler);
            return;
        }// end function

        public function cityReliveHandler(event:MouseEvent) : void
        {
            GameProxy.sceneProxy.relive(ERevival._ERevivalPoint);
            return;
        }// end function

        private function resGotHandler() : void
        {
            if (isDisposed)
            {
                return;
            }
            this._bmp1.bitmapData = GlobalClass.getBitmapData(ImagesConst.relive_LabelDD);
            this._bmp2.bitmapData = GlobalClass.getBitmapData(ImagesConst.relive_LabelMHFH);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._sectimer.stop();
            this._sectimer = null;
            this._bmp1.dispose(param1);
            this._bmp1 = null;
            this._bmp2.dispose(param1);
            this._bmp2 = null;
            this._text.dispose(param1);
            this._text = null;
            this._btn.dispose(param1);
            this._btn.filters = [];
            this._btn = null;
            return;
        }// end function

        public function setLeftTime(param1:int, param2:Function = null) : void
        {
            this._callback = param2;
            this._btn.enabled = false;
            this._btn.filters = [FilterConst.colorFilter];
            param1 = param1 + 1;
            if (param1 > 0)
            {
                this._total = param1;
                this._cur = 0;
                this._sectimer.start();
                this._text.text = (this._total - this._cur).toString();
            }
            else
            {
                this._total = 0;
                this._cur = 0;
                this.secTimerHandler(null);
            }
            return;
        }// end function

        private function secTimerHandler(param1:SecTimer) : void
        {
            var _loc_3:String = this;
            var _loc_4:* = this._cur + 1;
            _loc_3._cur = _loc_4;
            if (this._cur >= this._total)
            {
                this._sectimer.stop();
                this._btn.enabled = true;
                this._btn.filters = [];
                DisplayUtil.removeMe(this._bmp1);
                DisplayUtil.removeMe(this._bmp2);
                DisplayUtil.removeMe(this._text);
                if (this._callback != null)
                {
                    this._callback.apply();
                }
                return;
            }
            var _loc_2:* = (this._total - this._cur).toString();
            this._text.text = _loc_2;
            if (_loc_2.length == 1)
            {
                this._text.x = 75;
            }
            else if (_loc_2.length == 2)
            {
                this._text.x = 60;
            }
            else
            {
                this._text.x = 45;
            }
            return;
        }// end function

    }
}
